package com.nekonomics
package api.dto.response

import api.dto.util.SkuSpecUtil
import domain.detail.{CartItemDetail, SkuSpecDetail}
import types.Money

import zio.json.JsonEncoder


type t = Record {val t: String;}

case class CartItemDto(
  id: Long,
  skuId: Long,
  name: String,
  price: Money,
  quantity: Int,
  specs: String,
  imageUrl: Option[String]
) derives JsonEncoder

object CartItemDto {
  def of(ci: CartItemDetail, specs: List[SkuSpecDetail]): CartItemDto = {
    CartItemDto(
      id = ci.cartItemId,
      skuId = ci.skuId,
      name = ci.spuName,
      price = ci.price,
      quantity = ci.quantity,
      specs = SkuSpecUtil.fmtSpecs(specs),
      imageUrl = ci.imageUrl
    )
  }


}
